package movee.utils.threading;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;

/**
 * 不抛出异常的runnable封装类
 *
 * @author movee
 */
@Slf4j
public class WrappedRunnable implements Runnable {

    private final Runnable runnable;
    private final String message;

    public WrappedRunnable(final Runnable runnable) {
        this(runnable, "");
    }

    public WrappedRunnable(final Runnable runnable, final String message) {
        this.runnable = runnable;
        this.message = message;
    }

    @Override
    public void run() {
        try {
            runnable.run();
        } catch (Throwable t) {
            log.error("{}, exception info: {}", message, ExceptionUtils.getStackTrace(t));
        }
    }
}
